package com.niit.listener;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Arrays;

import javax.swing.JTable;

import com.niit.dao.BookDao;
import com.niit.dao.impl.BookDaoImpl;
import com.niit.entity.Book;
import com.niit.view.AddBookView;
import com.niit.view.MainView;
import java.sql.Timestamp;

public class ToUpdateListener extends MouseAdapter{
	private MainView view;
	private BookDao dao ;
	public ToUpdateListener(MainView view){
		this.view = view;
		this.dao = new BookDaoImpl();
	}
	//点击修改后
	@Override
	public void mouseClicked(MouseEvent e) {
		System.out.println("点击修改后");
		JTable dataTable = view.getDataTable();
		int row = dataTable.getSelectedRow();
		Object[] oArray = new Object[6];
		for(int i = 0;i<6;i++){
			Object v = dataTable.getValueAt(row, i);
			oArray[i] = v;
		}
		Book b = new Book((Integer)oArray[0], (Double)oArray[3], (String)oArray[1], (String)oArray[2], (String)oArray[4], (Timestamp)oArray[5]);
		UpdateListener listener = new UpdateListener(b);
		new AddBookView("修改",listener);
		this.view.dispose();
	}
}
